package com.ruoyi.activity.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.activity.mapper.ActivityMapper;
import com.ruoyi.activity.domain.Activity;
import com.ruoyi.activity.service.IActivityService;

/**
 * 营销活动Service业务层处理
 * 
 * @author 张富饶
 * @date 2025-05-21
 */
@Service
public class ActivityServiceImpl implements IActivityService 
{
    @Autowired
    private ActivityMapper activityMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询营销活动
     * 
     * @param id 营销活动主键
     * @return 营销活动
     */
    @Override
    public Activity selectActivityById(Long id)
    {
        Activity activity = activityMapper.selectActivityById(id);
        System.err.println(activity);
        Long creatorId = activity.getCreatorId();
        User user = userMapper.selectUserByUserId(creatorId);
        activity.setUser(user);
//        Long id1 = activity.getId();
//        User user = userMapper.selectUserByUserId(id1);
//        System.err.println(user);
//        activity.setUser(user);
//        System.err.println(activity);
        return activity;
    }

    /**
     * 查询营销活动列表
     * 
     * @param activity 营销活动
     * @return 营销活动
     */
    @Override
    public List<Activity> selectActivityList(Activity activity)
    {
        return activityMapper.selectActivityList(activity);
    }

    /**
     * 新增营销活动
     * 
     * @param activity 营销活动
     * @return 结果
     */
    @Override
    public int insertActivity(Activity activity)
    {
        activity.setCreateTime(DateUtils.getNowDate());
        return activityMapper.insertActivity(activity);
    }

    /**
     * 修改营销活动
     * 
     * @param activity 营销活动
     * @return 结果
     */
    @Override
    public int updateActivity(Activity activity)
    {
        activity.setUpdateTime(DateUtils.getNowDate());
        return activityMapper.updateActivity(activity);
    }

    /**
     * 批量删除营销活动
     * 
     * @param ids 需要删除的营销活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityByIds(Long[] ids)
    {
        return activityMapper.deleteActivityByIds(ids);
    }

    /**
     * 删除营销活动信息
     * 
     * @param id 营销活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityById(Long id)
    {
        return activityMapper.deleteActivityById(id);
    }
}
